package com.jsyl.lwbk.business.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.jsyl.lwbk.business.domain.CourseChildScore;
import com.jsyl.lwbk.business.handle.RestFullService;
import com.jsyl.lwbk.business.mapper.ChildMapper;
import com.jsyl.lwbk.business.mapper.ChildProjectConfigMapper;
import com.jsyl.lwbk.business.constant.ProjectCodeConstant;
import com.jsyl.lwbk.business.domain.Child;
import com.jsyl.lwbk.business.domain.ChildProjectConfig;
import com.jsyl.lwbk.business.domain.Integration;
import com.jsyl.lwbk.business.mapper.CourseChildScoreMapper;
import com.jsyl.lwbk.business.mapper.IntegrationMapper;
import com.jsyl.lwbk.common.utils.AgeUtils;
import com.jsyl.lwbk.common.utils.DateUtils;
import com.jsyl.lwbk.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 项目解锁规则
 *
 * @author Fitch
 * 2022/5/7
 */
@Service
public class UnlockRule {

    @Value("${si.url}")
    private String siApi;
    @Autowired
    private RestFullService restFullService;

    @Autowired
    private ChildProjectConfigMapper childProjectConfigMapper;
    @Autowired
    private CourseChildScoreMapper courseChildScoreMapper;
    @Autowired
    private IntegrationMapper integrationMapper;
    @Autowired
    private ChildMapper childMapper;


    public void unlock(Long childId, Long childCourseId, String projectCode, String score) {

        //学跳绳、学拍球、勾选‘已学会’  不再出现
        //学六边形跳、学动作、学肩上推举、学俯身划船、学硬拉、学弓步走、学平举 学勾选动作标准  不再出现
        if (ProjectCodeConstant.跳绳_学跳绳.equals(projectCode) ||
                ProjectCodeConstant.拍球_学拍球.equals(projectCode) ||
                ProjectCodeConstant.六边形跳_学六边形跳.equals(projectCode) ||
                ProjectCodeConstant.单手肩上投球_学动作.equals(projectCode) ||
                ProjectCodeConstant.肩上推举_学肩上推举.equals(projectCode) ||
                ProjectCodeConstant.俯身划船_学俯身划船.equals(projectCode) ||
                ProjectCodeConstant.硬拉训练_学硬拉.equals(projectCode) ||
                ProjectCodeConstant.弓步走_学弓步走.equals(projectCode) ||
                ProjectCodeConstant.平举_学平举.equals(projectCode)) {

            completeOnce(childId, projectCode, score);
            return;
        }

        List<Integer> leafType = new ArrayList<>();
        leafType.add(4);
        List<Integration> integrationList = this.integrationMapper.findList(leafType);
        Map<String, String> integrationName = new HashMap<>();
        for (Integration i : integrationList) {
            integrationName.put(i.getCode(), i.getName());
        }
        //课次 按照实际运动力上课次数
        int classTimes = this.courseChildScoreMapper.countClassTimes(childCourseId, childId);
        //老运动力课程数
        Map<String,Object> result = restFullService.get(siApi+"/score/countSchedule?childId="+childId,Map.class,null,null);
        if (result!=null && result.get("statusCode").equals("0000")) {
            classTimes+=StringUtils.getInt(StringUtils.getString(result.get("scheduleCount")));
        }
        unLockByTimes(childId, projectCode, integrationName);
        unLockByClassTimes(childId, projectCode, classTimes, integrationName);
        unLockByScore(childId, projectCode, classTimes, score, integrationName);

    }


    /**
     * 项目解锁--按完成次数解锁
     *
     * @param childId
     * @param projectCode
     */
    public void unLockByTimes(Long childId, String projectCode, Map<String, String> integrationName) {
        ChildProjectConfig config = this.childProjectConfigMapper.selectOne(childId, projectCode);
        //双脚跳-S0507   旋转解锁:纵向/横向各操作≥2次
        if (ProjectCodeConstant.双脚跳_双脚跳_横向.equals(projectCode) || ProjectCodeConstant.双脚跳_双脚跳_纵向.equals(projectCode)) {
            if (ProjectCodeConstant.双脚跳_双脚跳_纵向.equals(projectCode) && config.getCompleteTimes() >= 2) {
                config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.双脚跳_双脚跳_横向);
                if (config!=null && config.getCompleteTimes() >= 2) {
                    insertConfig(childId, ProjectCodeConstant.双脚跳_双脚跳_旋转, integrationName);
                }

            }
            if (ProjectCodeConstant.双脚跳_双脚跳_横向.equals(projectCode) && config.getCompleteTimes() >= 2) {
                config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.双脚跳_双脚跳_纵向);
                if (config!=null && config.getCompleteTimes() >= 2) {
                    insertConfig(childId, ProjectCodeConstant.双脚跳_双脚跳_旋转, integrationName);
                }
            }

        }

        //独脚椅-双手拍球 解锁： 独脚椅—单手拍球操作≥3次
        if (ProjectCodeConstant.独脚椅_单手拍球.equals(projectCode) && config.getCompleteTimes() >= 3) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.独脚椅_双手拍球);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.独脚椅_双手拍球, integrationName);
            }
        }
        //平衡台-托球/颠球,平衡台_对抛接球 解锁： 平衡台—拍球操作≥4次
        if (ProjectCodeConstant.平衡台_拍球.equals(projectCode) && config.getCompleteTimes() >= 4) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.平衡台_托球_颠球);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.平衡台_托球_颠球, integrationName);
            }
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.平衡台_对抛接球);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.平衡台_对抛接球, integrationName);
            }
        }

        //上抛接球_单手上抛，上抛接球_单手抛小球 解锁： 独脚椅—单手拍球操作≥3次
        if (ProjectCodeConstant.上抛接球_双手上抛.equals(projectCode) && config.getCompleteTimes() >= 3) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.上抛接球_单手上抛);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.上抛接球_单手上抛, integrationName);
            }
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.上抛接球_单手抛小球);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.上抛接球_单手抛小球, integrationName);
            }
        }

        //上抛接球_多小球上抛 解锁：
        //1、上抛接球（含所有）操作≥15次；
        //2、课时≥30次；
        //3、其他上抛操作种类各≥4次

        //对抛接球_单手对抛 解锁：反手对抛 操作≥5次
        if (ProjectCodeConstant.对抛接球_反手对抛.equals(projectCode) && config.getCompleteTimes() >= 5) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.对抛接球_单手对抛);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.对抛接球_单手对抛, integrationName);
            }
        }

        //俯身划船_实心球 解锁：操作基本动作8次以上
        if (ProjectCodeConstant.俯身划船_基本动作.equals(projectCode) && config.getCompleteTimes() >= 8) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.俯身划船_实心球);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.俯身划船_实心球, integrationName);
            }
        }
        //俯身划船_牛角包 解锁：操作实心球动作8次以上
        if (ProjectCodeConstant.俯身划船_实心球.equals(projectCode) && config.getCompleteTimes() >= 8) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.俯身划船_牛角包);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.俯身划船_牛角包, integrationName);
            }
        }

        //硬拉训练_牛角包 解锁：操作基本动作8次以上
        if (ProjectCodeConstant.硬拉训练_基本动作.equals(projectCode) && config.getCompleteTimes() >= 8) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.硬拉训练_牛角包);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.硬拉训练_牛角包, integrationName);
            }
        }

        //下蹲_窄距蹲起 解锁：操作基本动作8次以上
        if (ProjectCodeConstant.下蹲_蹲起.equals(projectCode) && config.getCompleteTimes() >= 8) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.下蹲_窄距蹲起);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.下蹲_窄距蹲起, integrationName);
            }
        }
        //下蹲_弓箭蹲 解锁：操作基本动作8次以上
        if (ProjectCodeConstant.下蹲_窄距蹲起.equals(projectCode) && config.getCompleteTimes() >= 4) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.下蹲_弓箭蹲);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.下蹲_弓箭蹲, integrationName);
            }
        }
        if (projectCode.indexOf(ProjectCodeConstant.下蹲类)>-1) {
            int total = this.childProjectConfigMapper.sumProjectTimes(childId, ProjectCodeConstant.下蹲类);
            if (total >=20) {
                insertConfig(childId, ProjectCodeConstant.下蹲_半静蹲, integrationName);
            }
        }

        //平举_沙包 解锁：操作基本动作4次以上
        if (ProjectCodeConstant.平举_基本动作.equals(projectCode) && config.getCompleteTimes() >= 4) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.平举_沙包);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.平举_沙包, integrationName);
            }
        }
        //平举_哑铃 解锁：操作平举+沙包8次以上
        if (ProjectCodeConstant.平举_基本动作.equals(projectCode) || ProjectCodeConstant.平举_沙包.equals(projectCode)) {
            int sum = 0;
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.平举_基本动作);
            if(config !=null){
                sum += config.getCompleteTimes();
            }
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.平举_沙包);
            if(config !=null){
                sum += config.getCompleteTimes();
            }
            if (sum >= 8) {
                config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.平举_哑铃);
                if (config == null) {
                    insertConfig(childId, ProjectCodeConstant.平举_哑铃, integrationName);
                }
            }
        }

        //蹦床_蹦床_对抛抛球 解锁：操作10次以上
        if (projectCode.indexOf(ProjectCodeConstant.蹦床类)>-1) {
            int total = this.childProjectConfigMapper.sumProjectTimes(childId, ProjectCodeConstant.蹦床类);
            if (total>=10) {
                insertConfig(childId, ProjectCodeConstant.蹦床_蹦床_对抛抛球, integrationName);
            }
        }
        //蹦床_跳绳 解锁：蹦床_对抛接球操作≥6次解锁
        if (projectCode.equals(ProjectCodeConstant.蹦床_蹦床_对抛抛球) && config.getCompleteTimes() >= 6) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.蹦床_蹦床_跳绳);
            if (config ==null) {
                insertConfig(childId, ProjectCodeConstant.蹦床_蹦床_跳绳, integrationName);
            }
        }
        //平衡脚踏车_平衡脚踏车倒走 解锁：平衡脚踏车_平衡脚踏车正走4次以上
        if (ProjectCodeConstant.平衡脚踏车_平衡脚踏车正走.equals(projectCode) && config.getCompleteTimes() >= 4) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.平衡脚踏车_平衡脚踏车倒走);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.平衡脚踏车_平衡脚踏车倒走, integrationName);
            }
        }
        //平衡脚踏车_平衡脚踏车顶物走 解锁：平衡脚踏车_平衡脚踏车正走4次以上
        if (ProjectCodeConstant.平衡脚踏车_平衡脚踏车倒走.equals(projectCode) && config.getCompleteTimes() >= 3) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.平衡脚踏车_平衡脚踏车顶物);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.平衡脚踏车_平衡脚踏车顶物, integrationName);
            }
        }
        //6-10岁对抛接球_反手对抛 解锁：对抛接球_双手对抛6次以上
        if (ProjectCodeConstant.对抛接球_双手对抛.equals(projectCode) && config.getCompleteTimes() >= 6) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.对抛接球_反手对抛);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.对抛接球_反手对抛, integrationName);
            }
        }

    }


    public void unLockByClassTimes(Long childId, String projectCode, Integer classTimes, Map<String, String> integrationName) {
        /**
         * 【大滑板_抓物】【大滑板_投篮】 【大滑板_口算】 【大滑板_抛球】 解锁
         */
        if (classTimes >= 29) {
            insertConfig(childId, ProjectCodeConstant.大滑板_抓物, integrationName);
            insertConfig(childId, ProjectCodeConstant.大滑板_投篮, integrationName);
            insertConfig(childId, ProjectCodeConstant.大滑板_口算, integrationName);
            insertConfig(childId, ProjectCodeConstant.大滑板_抛球, integrationName);
        }


        //上抛接球_多小球上抛 解锁 1、上抛接球（含所有）操作≥15次；2、课时≥30次； 3、其他上抛操作种类各≥4次
        if (projectCode.indexOf(ProjectCodeConstant.上抛接球类) > -1 && classTimes >= 30) {
            int totalCount = this.childProjectConfigMapper.sumProjectTimes(childId, ProjectCodeConstant.上抛接球类);
            if (totalCount >= 15) {
                List<String> projectCodes = new ArrayList<>();
                projectCodes.add(ProjectCodeConstant.上抛接球_双手上抛);
                projectCodes.add(ProjectCodeConstant.上抛接球_单手上抛);
                projectCodes.add(ProjectCodeConstant.上抛接球_单手抛小球);
                int temp = this.childProjectConfigMapper.countProjectTimes(childId, projectCodes, 4);
                if (temp >= projectCodes.size()) {
                    insertConfig(childId, ProjectCodeConstant.上抛接球_多小球上抛, integrationName);
                }
            }

        }


    }

    public void unLockByScore(Long childId, String projectCode, Integer classTimes, String score, Map<String, String> integrationName) {
        ChildProjectConfig config = this.childProjectConfigMapper.selectOne(childId, projectCode);
        //【交替拍球】解锁：【定点拍球】做过（出现且被记录）≥2次；且持续拍球量≥50个出现过≥1次 解锁【交替拍球】
        if (projectCode.equals(ProjectCodeConstant.拍球_定点拍球) && config.getCompleteTimes() >= 2) {
            //当前成绩判断
//            JSONObject json = JSONObject.parseObject(score);
//            if (StringUtils.isNotEmpty(String.valueOf(json.get("cxpqgs")))) {
//                if (Integer.valueOf(json.get("cxpqgs").toString()) >= 50) {
//                    insertConfig(childId, ProjectCodeConstant.拍球_交替拍球, integrationName);
//                    return;
//                }
//            }
            //历史成绩判断
            List<CourseChildScore> scoreList = this.courseChildScoreMapper.listScoreByCode(childId, projectCode);
            for (CourseChildScore courseChildScore : scoreList) {
                JSONObject json = JSONObject.parseObject(courseChildScore.getScore());
                if (json!=null &&json.containsKey("cxpqgs")&&StringUtils.isNotEmpty(String.valueOf(json.get("cxpqgs")))) {
                    if (Integer.valueOf(json.get("cxpqgs").toString()) >= 50) {
                        insertConfig(childId, ProjectCodeConstant.拍球_交替拍球, integrationName);
                    }
                }
            }
        }

        //【拍跨球】解锁：【交替拍球】持续拍球≥50个，解锁【拍跨球】
        if (projectCode.equals(ProjectCodeConstant.拍球_交替拍球)) {
            //当前成绩判断
//            JSONObject json = JSONObject.parseObject(score);
//            if (StringUtils.isNotEmpty(String.valueOf(json.get("cxpqgs")))) {
//                if (Integer.valueOf(json.get("cxpqgs").toString()) >= 50) {
//                    insertConfig(childId, ProjectCodeConstant.拍球_拍跨球, integrationName);
//                    return;
//                }
//            }
            //历史成绩判断
            List<CourseChildScore> scoreList = this.courseChildScoreMapper.listScoreByCode(childId, projectCode);
            for (CourseChildScore courseChildScore : scoreList) {
                JSONObject json = JSONObject.parseObject(courseChildScore.getScore());
                if (json!=null &&json.containsKey("cxpqgs")&&StringUtils.isNotEmpty(String.valueOf(json.get("cxpqgs")))) {
                    if (Integer.valueOf(json.get("cxpqgs").toString()) >= 50) {
                        insertConfig(childId, ProjectCodeConstant.拍球_拍跨球, integrationName);
                    }
                }
            }
        }

        /**
         * 【平衡拍球、加高拍球解锁】
         * 1、拍球≥10次；
         * 2、完成【定点拍球】≥3次，且最高记录连续≥100个；
         * 3、完成【交替拍球】≥3次，且最高记录连续≥50个。
         * 4、以上全部满足
         */
        if (projectCode.indexOf(ProjectCodeConstant.拍球_拍球类) > -1) {
            int total = this.childProjectConfigMapper.sumProjectTimes(childId, ProjectCodeConstant.拍球_拍球类);
            if (total >= 10) {
                ChildProjectConfig config1 = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.拍球_定点拍球);
                ChildProjectConfig config2 = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.拍球_交替拍球);
                if (config1 !=null && config2!=null && config1.getCompleteTimes() >= 3 && config2.getCompleteTimes() >= 3) {
//                        JSONObject json = JSONObject.parseObject(score);
//                        if (String.valueOf(json.get("cxpqgs")) != null && String.valueOf(json.get("cxpqgs")) != "") {
//                            if (Integer.valueOf(json.get("cxpqgs").toString()) >= 100) {
//                                List<CourseChildScore> scoreList = this.courseChildScoreMapper.listScoreByCode(childId, ProjectCodeConstant.拍球_交替拍球);
//                                for (CourseChildScore courseChildScore : scoreList) {
//                                    json = JSONObject.parseObject(courseChildScore.getScore());
//                                    if (String.valueOf(json.get("cxpqgs")) != null && String.valueOf(json.get("cxpqgs")) != "") {
//                                        if (Integer.valueOf(json.get("cxpqgs").toString()) >= 50) {
//                                            insertConfig(childId, ProjectCodeConstant.拍球_拍跨球, integrationName);
//                                            return;
//                                        }
//                                    }
//                                }
//
//                            }
//                        }
                    //定点拍球：最高连续>=100，交替拍球：最高记录连续≥50个
                    List<CourseChildScore> scoreList = this.courseChildScoreMapper.listScoreByCode(childId, ProjectCodeConstant.拍球_定点拍球);
                    for (CourseChildScore courseChildScore : scoreList) {
                        JSONObject json = JSONObject.parseObject(courseChildScore.getScore());
                        if (json!=null &&json.containsKey("cxpqgs")&&StringUtils.isNotEmpty(String.valueOf(json.get("cxpqgs")))) {
                            if (Integer.valueOf(json.get("cxpqgs").toString()) >= 100) {
                                List<CourseChildScore> scoreList1 = this.courseChildScoreMapper.listScoreByCode(childId, ProjectCodeConstant.拍球_交替拍球);
                                for (CourseChildScore courseChildScore1 : scoreList1) {
                                    json = JSONObject.parseObject(courseChildScore1.getScore());
                                    if (json!=null &&json.containsKey("cxpqgs")&&StringUtils.isNotEmpty(String.valueOf(json.get("cxpqgs")))) {
                                        if (Integer.valueOf(json.get("cxpqgs").toString()) >= 50) {
                                            insertConfig(childId, ProjectCodeConstant.拍球_平衡拍球, integrationName);
                                            insertConfig(childId, ProjectCodeConstant.拍球_加高拍球, integrationName);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }

                }


            }

        }


        /**
         * 【双脚交替跳绳】解锁：
         * 1、跳绳-基本动作≥8次；
         * 2、基本动作最高成绩≥100个/分
         *
         */
        if (projectCode.equals(ProjectCodeConstant.跳绳_基本动作) && config.getCompleteTimes() >= 7) {
            //当前成绩判断
//            JSONObject json = JSONObject.parseObject(score);
//            if (String.valueOf(json.get("yfzgs")) != null && String.valueOf(json.get("yfzgs")) != "") {
//                if (Integer.valueOf(json.get("yfzgs").toString()) >= 100) {
//                    insertConfig(childId, ProjectCodeConstant.跳绳_双脚交替跳绳, integrationName);
//                    return;
//                }
//            }
            //历史成绩判断
            List<CourseChildScore> scoreList = this.courseChildScoreMapper.listScoreByCode(childId, projectCode);
            for (CourseChildScore courseChildScore : scoreList) {
                JSONObject json = JSONObject.parseObject(courseChildScore.getScore());
                if (json!=null &&json.containsKey("yfzgs")&&StringUtils.isNotEmpty(String.valueOf(json.get("yfzgs")))) {
                    if (Integer.valueOf(json.get("yfzgs").toString()) >= 100) {
                        insertConfig(childId, ProjectCodeConstant.跳绳_双脚交替跳绳, integrationName);
                    }
                }
            }

        }

        /**
         * 【跳绳_单脚跳】解锁：跳绳-交替跳绳出现≥2次
         */
        if (projectCode.equals(ProjectCodeConstant.跳绳_双脚交替跳绳) && config.getCompleteTimes() >= 2) {
            config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.跳绳_单脚跳);
            if (config == null) {
                insertConfig(childId, ProjectCodeConstant.跳绳_单脚跳, integrationName);
            }
        }

        /**
         * 【跳绳_双摇】【跳绳_双人跳】 解锁：
         * 1、跳绳-单脚跳选择≥2次；
         * 2、跳绳操作累计≥15次；
         * -- 3、跳绳基本动作最高成绩≥100个/分；---可不判断：和1是递进关系 1满足3必满足
         * 4、总课时≥30节课
         */
        if (projectCode.indexOf(ProjectCodeConstant.跳绳类) > -1 && classTimes >= 29) {
            int total = this.childProjectConfigMapper.sumProjectTimes(childId, ProjectCodeConstant.跳绳类);
            if (total >= 14) {
                ChildProjectConfig config1 = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.跳绳_单脚跳);

                if ((projectCode.equals(ProjectCodeConstant.跳绳_单脚跳) && config1!=null &&  config1.getCompleteTimes() >= 1) ||
                        (!projectCode.equals(ProjectCodeConstant.跳绳_单脚跳) && config1!=null && config1.getCompleteTimes() >= 2)) {
                    config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.跳绳_双摇);
                    if (config == null) {
                        insertConfig(childId, ProjectCodeConstant.跳绳_双摇, integrationName);
                    }
                    config = this.childProjectConfigMapper.selectOne(childId, ProjectCodeConstant.跳绳_双人跳);
                    if (config == null) {
                        insertConfig(childId, ProjectCodeConstant.跳绳_双人跳, integrationName);
                    }
                }
            }
        }

    }

    /**
     * 学类  只出现一次
     *
     * @param childId
     * @param projectCode
     * @param score
     */
    public void completeOnce(Long childId, String projectCode, String score) {
        ChildProjectConfig config = childProjectConfigMapper.selectOne(childId, projectCode);
        if(config ==null){
            return;
        }
        JSONObject json = JSONObject.parseObject(score);
        if (json!=null &&json.containsKey("yxh") && json.get("yxh").toString().equals("on")) {
            config.setStatus(2);
            this.childProjectConfigMapper.update(config);
        }
        if (json!=null &&json.containsKey("dzbz") && json.get("dzbz").toString().equals("on")) {
            config.setStatus(2);
            this.childProjectConfigMapper.update(config);
        }
    }

    /**
     * 解锁项目
     *
     * @param childId
     * @param projectCode
     */
    private void insertConfig(Long childId, String projectCode, Map<String, String> integrationName) {
        Child child =this.childMapper.selectById(childId);
        int age = AgeUtils.computationsAge(child.getBirthYear(),child.getBirthMonth());
        //判断是否已解锁且是否在年龄范围之内
        ChildProjectConfig local = this.childProjectConfigMapper.getProjectInfo(childId, projectCode,age);
        if (local != null && local.getId() ==null) {
            ChildProjectConfig config;
            config = new ChildProjectConfig();
            config.setId(IdWorker.getId());
            config.setDifficultyLevel(1);
            config.setChildId(childId);
            config.setProjectCode(projectCode);
            config.setProjectName(integrationName.get(projectCode));
            config.setStatus(0);
            config.setCompleteTimes(0);
            config.setCreateTime(DateUtils.getNowDate());
            this.childProjectConfigMapper.insert(config);
        }
    }

}
